import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from 'axios';
import moment from 'moment';

Vue.config.productionTip = false;

axios.defaults.baseURL = 'http://127.0.0.1:7001';
axios.interceptors.request.use(config => {
  if (config.push !== '/') {
    if (sessionStorage.getItem('token')) {
      config.headers.Authorization = `Bearer ${sessionStorage.getItem('token')}`;
    }
  }
  return config;
}, error => {
  return Promise.reject(error);
});
axios.interceptors.response.use(res => {
  if (res.data && res.data.code == 403) {
    sessionStorage.removeItem('token');
    router.push('/login');
  } else {
    return res;
  }
}, error => {
  return Promise.reject(error);
});
Vue.prototype.axios = axios;
Vue.prototype.moment = moment;

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
